<?php
session_start();
$content=simplexml_load_file("../catalog.xml");
$marcaObiect = $content->marca;
$result = '';

$marcaID = $_POST['marca'];
$modelID = $_POST['model'];
$generatieID = $_POST['generatie'];

/*
$marcaID = 'audi';
$modelID = 'a4';
$generatieID = '1994-2001';
*/
foreach($marcaObiect as $marca) {
	$numeMarca=$marca->numeMarca;
	if (strtolower ($numeMarca) == $marcaID) {
		$result["marca"] = $numeMarca;
		$modelObiect = $marca->model;
		foreach($modelObiect as $model) {
		$numeModel = $model->numeModel;
		if (strtolower($numeModel) == $modelID) {
				$generatieObiect = $model->generatie;
				foreach($generatieObiect as $generatie) {
					$aniProductie = $generatie->aniProductie;
					if (strtolower($aniProductie) == $generatieID) {
						$detaliiObject = $generatie->detalii;
						foreach($detaliiObject as $detalii) {
							$detaliiID = $detalii->attributes()->id;
							$numePiesa = $detalii->numePiesa;
							$imaginePiesa = $detalii->imaginePiesa;
							$pret = $detalii->pret;?>
							<div class="detailsLine">
								<div class="detailImage">
								<img src="<?php echo $imaginePiesa; ?>" class="detailImageDiv" />
								</div>
								<div class="detailName">
									<?php echo $numePiesa; ?>
								</div>
								<div class="detailPrice">
									<?php echo $pret; ?>
								</div>
								<div class="sterge">
									<?php if (isset($_SESSION['loggedIn'])) { ?>
									<button class="delete" id="<?php echo $detaliiID; ?>">Sterge</button>
									<button class="modifica" id="<?php echo $detaliiID; ?>">Modifica</button>
									<?php } ?>
								</div>
							</div>
							<br />
							<?php
						}
					}
				}
			}
		}
	}
}
?>